'use strict';

const jwt = require('jsonwebtoken');

export default class extends think.Controller {
	async __before() {
		let that = this
		const token = that.ctx.header['user-token']
		if (token) {
			//验证token
			try {
				const res = jwt.verify(token,think.config('mytmini.jwtSecret'))
				think.openid = res.openid
			} catch (e) {
				return that.json({statusCode: '100',msg: '身份验证失败,请重新验证'})
			}
		
		}
	}

	// 获取当前登录用户openid
	getuseropenid() {
		return think.openid
	}
}